<template>
  <div class="app-container">
    <el-card shadow="never" class="mb20">
      <div class="filter-container">
        <div class="filter-item">
          <label class="radio-label">创建时间：</label>
          <el-date-picker
            v-model="dateRange"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </div>
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter"></el-button>
        <el-button class="filter-item" icon="el-icon-refresh-left" @click="handleReset"></el-button>
      </div>
    </el-card>
    <el-table
      :data="list"
      row-key="processTypeId"
      border
      stripe
      fit
      highlight-current-row>
      <el-table-column prop="processTypeName" label="分类" min-width="200" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="handleView(scope.row)">{{scope.row.processTypeName}}</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="total" label="总流程数" min-width="100" align="center">
      </el-table-column>
      <el-table-column prop="unFinishTotal" label="正在执行" min-width="100" align="center">
      </el-table-column>
      <el-table-column prop="finishTotal" label="已完成" min-width="100" align="center">
      </el-table-column>
      <el-table-column label="操作" min-width="80" align="center">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            circle
            icon="el-icon-view"
            title="查看该分类流程"
            @click="handleView(scope.row)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<!--流程监控-->
<script>
import { queryProcessStatistics } from '@/api/workflow/bpmn/runtime'
import moment from 'moment'

export default {
  components: { 
  },
  data() {
    return {
      dateRange: '',
      list: []
    }
  },
  filters: {},
  created() {
    this.fetchData()
  },
  methods: {
    handleFilter() {
      // this.listQuery.pageNo = 1
      this.fetchData()
    },
    handleReset() {
      this.dateRange = ''
      this.handleFilter()
    },
    fetchData() {
      const post = { }
      if (this.dateRange && this.dateRange.length === 2) {
        post.startTime = moment(this.dateRange[0]).format('YYYY-MM-DD')
        post.endTime = moment(this.dateRange[1]).format('YYYY-MM-DD')
      }
      queryProcessStatistics(post).then(response => {
        this.list = response.data
      })
    },
    handleView(row) { // 查看分类下的流程
      this.$router.push({ 
        path: '/workflow/watch/classify',
        query: { 
          processTypeId: row.processTypeId,
        }
      })
    }
  }
}
</script>
